package cn.dynamicdll
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	public class EventHandler implements IEventDispatcher
	{
		private static var _instan:EventHandler = null;
		private var _eventdispatcher:EventDispatcher;
		public static function getInstance():EventHandler
		{
			if(_instan == null)
				_instan = new EventHandler(new Singleton);
			return _instan;
		}
		public function EventHandler(singleton:Singleton)
		{
			super();
			if(singleton == null)
			{
				throw new Error("This is singleton pattern!");
				return;
			}
			this._eventdispatcher = new EventDispatcher();
		}
		public function addEventListener(type:String, listener:Function, 
										 useCapture:Boolean=false, priority:int=0, 
										 useWeekReference:Boolean = false):void
		{
			_eventdispatcher.addEventListener(type, listener, useCapture, priority, useWeekReference);
		}
		public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void
		{
			_eventdispatcher.removeEventListener(type, listener, useCapture);
		}
		public function hasEventListener(type:String):Boolean
		{
			return _eventdispatcher.hasEventListener(type);
		}
		public function dispatchEvent(event:Event):Boolean
		{
			return _eventdispatcher.dispatchEvent(event);
		}
		public function willTrigger(type:String):Boolean
		{
			return _eventdispatcher.willTrigger(type);
		}
		public static function dispatchEvent(event:Event):Boolean
		{
			return EventHandler.getInstance().dispatchEvent(event);
		}
	}
}
class Singleton{}
